<?php
require_once '../config.php';
require_once '../dao/dao_db.php';
require_once '../dao/dao_schedule.php';
session_start();
session_cache_limiter('private');
if(isset($_POST['lesson_index'])){
	$lesson_index = $_POST['lesson_index'];
}else if(isset($_GET['lesson_index'])){
	$lesson_index = $_GET['lesson_index'];
}else{
	$lesson_index='';
}
if(isset($_POST['lesson_name'])){
	$lesson_name  = trim($_POST['lesson_name']);
}else{
	$lesson_name='';
}
if(isset($_POST['startweek'])&&$_POST['startweek']!=''){
	$startweek=$_POST['startweek'];
}else{
	$startweek='';
}
if(isset($_POST['endweek'])&&$_POST['endweek']){
	$endweek=$_POST['endweek'];
}else{
	$endweek='';
}
$userid	= $_SESSION['userid'];
if($userid!=''){
	if($lesson_name!=''&&$lesson_index!=''){
		$result=get_schedule($userid,$lesson_index);
		if(mysql_num_rows($result)==0){
			save_schedule($userid,$lesson_index,$lesson_name,$startweek,$endweek);
		}else{
			update_schedule($userid,$lesson_index,$lesson_name,$startweek,$endweek);
		}
	}elseif(isset($_GET['lesson_index'])){
		$result=get_schedule($userid,$lesson_index);
		$row=mysql_fetch_array($result);
		echo $row['LESSONNAME']."<br/>";
		if($row['STARTWEEK']!=''&&$row['ENDWEEK']!=''){
			echo '('.$row['STARTWEEK'].'-'.$row['ENDWEEK'].')';
		}
	}
	mysql_close();
}else{
	header("LOCATION:../login.php");
}

?>